/*-------------------------------------------------------------------------
 * CLR版本:     4.0.30319.42000
 * 创建人:      song
 * 创建时间：   2024/4/9 17:56:20
 * 功 能：      绘制器基类
 *-------------------------------------------------------------------------*/

#if UNITY_EDITOR
namespace SCore.Editor.SShaderDraw
{
    using System.Collections.Generic;
    using UnityEditor;
    using UnityEngine;

    public abstract class SPropSuperBase<T> : SPropBase
    {
        protected T defaultValue;

        public SPropSuperBase(string name, GUIContent lable, MaterialEditor materialEditor,
            Dictionary<string, MaterialProperty> props, T defaultValue, GUIStyle guiStyle = null) :
            base(name, lable, materialEditor, props, guiStyle)
        {
            this.defaultValue = defaultValue;
        }

        protected void DrawResetBtn(float btnSize, resetFunc func)
        {
            GUI.color = ResetBtnColor;
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(btnSize) };
            if (GUILayout.Button("重置", options))
            {
                func();
            }

            GUI.color = Color.white;
        }

        protected delegate void resetFunc();

        protected abstract T getValue();
        protected abstract void setValue(T value);

        public T Value
        {
            get
            {
                if (base.props.ContainsKey(base.name))
                {
                    return this.getValue();
                }

                return this.defaultValue;
            }
            set
            {
                if (base.props.ContainsKey(base.name))
                {
                    this.setValue(value);
                }
            }
        }

        public bool BoolValue
        {
            get
            {
                if (base.props.ContainsKey(base.name))
                {
                    MaterialProperty prop = base.props[base.name];
                    return prop.floatValue > 0f;
                }

                return false;
            }
        }
    }
}
#endif